﻿using DatabaseCore.Dto;
using NawaData;
using NawaData.Dao;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DatabaseCore.Dao
{
    public class ProductMovementDaocs
    {
        public List<TransectionWithMoveType> getMoveTypeByPalletIds(List<decimal> PalletIds)
        {
            using (var db = new ExportDBEntities())
            {
                List<TransectionWithMoveType> allMoves = new List<TransectionWithMoveType>();
                var moveDeatils = (from move in db.ProductMovementTemp
                                  where PalletIds.Contains(move.PalletDetailID)
                                  select move).ToList();

                var typeProvider = new MovementTypeDao();
                var allMove = typeProvider.getMoveTypeByPallet(moveDeatils.Select(m=>m.MovementType).ToArray());
                foreach (var move in moveDeatils)
                {
                    foreach (var type in allMove)
                    {
                        if (move.MovementType == type.mmovtype)
                        {
                            allMoves.Add(new TransectionWithMoveType(){MoveType = type.mmovtype,
                                MReverse = type.mreverse,
                                MSubCate =type.mmovsubcate,
                            PalletId = move.PalletDetailID});
                        }
                    }
                }
                return allMoves;
            }
        }
    }
}
